import router, { constantRoutes } from "./index";
import { siteTitle, siteLoginRouter } from "@/settings";
import { getStorage, setStorage } from "@/utils/common";
const whiteList = siteLoginRouter;

router.beforeEach(async (to, from, next) => {
  const token = getStorage(`${siteTitle}_token`);
  if (token) {
    next();
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      setStorage(`${siteTitle}_tabarRouter`, 0);
      next({
        path: "/home",
        query: { uid: Math.random(), fullPath: to.fullPath },
      });
    }
  }
});
